home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / Marlais 0.3.1 / gc4.1-mac / src / setjmp_t.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  3.9 KB  |  160 lines  |  [TEXT/R*ch]

  1. /*
  2.  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
  3.  *
  4.  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  5.  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
  6.  *
  7.  * Permission is hereby granted to use or copy this program
  8.  * for any purpose,  provided the above notices are retained on all copies.
  9.  * Permission to modify the code and to distribute modified code is granted,
  10.  * provided the above notices are retained, and a notice that the code was
  11.  * modified is included with the above copyright notice.
  12.  */
  13. /* Boehm, May 19, 1994 2:01 pm PDT */
  14.  
  15. /* Check whether setjmp actually saves registers in jmp_buf. */
  16. /* If it doesn't, the generic mark_regs code won't work.     */
  17. /* Compilers vary as to whether they will put x in a          */
  18. /* (callee-save) register without -O.  The code is         */
  19. /* contrived such that any decent compiler should put x in   */
  20. /* a callee-save register with -O.  Thus it is is          */
  21. /* recommended that this be run optimized.  (If the machine  */
  22. /* has no callee-save registers, then the generic code is    */
  23. /* safe, but this will not be noticed by this piece of       */
  24. /* code.)                             */
  25. #include <stdio.h>
  26. #include <setjmp.h>
  27. #include "config.h"
  28.  
  29. #ifdef __hpux
  30. /* X/OPEN PG3 defines "void* sbrk();" and this clashes with the definition */
  31. /* in gc_private.h, so we set the clock backwards with _CLASSIC_XOPEN_TYPES. */
  32. /* This is for HP-UX 8.0.
  33. /* sbrk() is not used in this file, of course.  W. Underwood, 15 Jun 1992 */
  34. #define _CLASSIC_XOPEN_TYPES
  35. #include <unistd.h>
  36. int
  37. getpagesize()
  38. {
  39.     return sysconf(_SC_PAGE_SIZE);
  40. }
  41. #endif
  42.  
  43. #if defined(SUNOS5)
  44. #define _CLASSIC_XOPEN_TYPES
  45. #include <unistd.h>
  46. int
  47. getpagesize()
  48. {
  49.     return sysconf(_SC_PAGESIZE);
  50. }
  51. #endif
  52.  
  53. #ifdef _AUX_SOURCE
  54. #include <sys/mmu.h>
  55. int
  56. getpagesize()
  57. {
  58.    return PAGESIZE;
  59. }
  60. #endif
  61.  
  62. #ifdef AMIGA
  63. int
  64. getpagesize()
  65. {
  66.     return(4096);
  67. }
  68. #endif
  69.  
  70. #ifdef MACINTOSH
  71. int
  72. getpagesize()
  73. {
  74.     return(4096);
  75. }
  76. #endif
  77.  
  78. #ifdef __OS2__
  79. #define INCL_DOSFILEMGR
  80. #define INCL_DOSMISC
  81. #define INCL_DOSERRORS
  82. #include <os2.h>
  83.  
  84. int
  85. getpagesize()
  86. {
  87.     ULONG result[1];
  88.     
  89.     if (DosQuerySysInfo(QSV_PAGE_SIZE, QSV_PAGE_SIZE,
  90.                     (void *)result, sizeof(ULONG)) != NO_ERROR) {
  91.         fprintf(stderr, "DosQuerySysInfo failed\n");
  92.         result[0] = 4096;
  93.     }
  94.     return((int)(result[0]));
  95. }
  96. #endif
  97.  
  98. struct {char a_a; char * a_b;} a;
  99.  
  100. int * nested_sp()
  101. {
  102.     int dummy;
  103.     
  104.     return(&dummy);
  105. }
  106.  
  107. main()
  108. {
  109.     int dummy;
  110.     long ps = getpagesize();
  111.     jmp_buf b;
  112.     register int x = strlen("a");  /* 1, slightly disguised */
  113.     static int y = 0;
  114.  
  115.     if (nested_sp() < &dummy) {
  116.       printf("Stack appears to grow down, which is the default.\n");
  117.       printf("A good guess for STACKBOTTOM on this machine is 0x%X.\n",
  118.              ((long)(&dummy) + ps) & ~(ps-1));
  119.     } else {
  120.       printf("Stack appears to grow up.\n");
  121.       printf("Define STACK_GROWS_UP in gc_private.h\n");
  122.       printf("A good guess for STACKBOTTOM on this machine is 0x%X.\n",
  123.              ((long)(&dummy) + ps) & ~(ps-1));
  124.     }
  125.     printf("Note that this may vary between machines of ostensibly\n");
  126.     printf("the same architecture (e.g. Sun 3/50s and 3/80s).\n");
  127.     printf("A good guess for ALIGNMENT on this machine is %d.\n",
  128.            (unsigned long)(&(a.a_b))-(unsigned long)(&a));
  129.     
  130.     /* Encourage the compiler to keep x in a callee-save register */
  131.     x = 2*x-1;
  132.     printf("");
  133.     x = 2*x-1;
  134.     setjmp(b);
  135.     if (y == 1) {
  136.         if (x == 2) {
  137.         printf("Generic mark_regs code probably wont work\n");
  138. #        if defined(SPARC) || defined(RS6000) || defined(VAX) || defined(MIPS) || defined(M68K) || defined(I386) || defined(NS32K) || defined(RT)
  139.             printf("Assembly code supplied\n");
  140. #        else
  141.             printf("Need assembly code\n");
  142. #        endif
  143.         } else if (x == 1) {
  144.         printf("Generic mark_regs code may work\n");
  145.         } else {
  146.         printf("Very strange setjmp implementation\n");
  147.         }
  148.     }
  149.     y++;
  150.     x = 2;
  151.     if (y == 1) longjmp(b,1);
  152.     return(0);
  153. }
  154.  
  155. int g(x)
  156. int x;
  157. {
  158.     return(x);
  159. }
  160.